from params import *
from register import *
from utils import define_print, print_len

# name: id
PR_IDS = {
    'PR_QC': 0x0,
    'PR_Q': 0x1,
    'PR_QS2': 0x2,
    'PR_M1': 0x3,
    'PR_RR': 0x4,
    'PR_1': 0x5,
    'PR_2': 0x6,
    'PR_3': 0x7,
}


class Instruction:
    def __init__(self, inst_name, param1=0, param2=0, param3=0, func_name=''):
        self.name = inst_name

        self.function_name = func_name
        self.param1 = param1
        self.param2 = param2
        self.param3 = param3

    def __str__(self):
        return str([self.name, self.function_name, self.param1, self.param2, self.param3])

    def __repr__(self):
        return str(self)

    def to_hex_str(self):
        # 8 bits
        res = INST_REGISTERS[self.name] << 56
        # 8 bits
        if self.name == 'CALL' and self.function_name != '':
            res += get_function_id_by_name(self.function_name) << 48
        # 16 bits
        res += self.param1 << 32
        res += self.param2 << 16
        res += self.param3

        assert 0 <= res < pow(2, ROM_DATA_WIDTH)

        return '%016x' % res


def gen_PR_IDs():
    for PR, ID in PR_IDS.items():
        define_print(f'{PR}_ID', f'4\'h{ID:x}')


def rst_pr():
    for PR in PR_IDS.keys():
        for i in range(6):
            print_len(f'{PR}[{i}]', '', 10)
            print('<= 0;', end=' ')
        print()

if __name__ == '__main__':
    rst_pr()